<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>WebSocket 简易聊天室</title>
    <script type="text/javascript" src="/js/jquery.js"></script>
    <script type="text/javascript" src="/js/socket.js"></script>
    <script>
        let username = prompt("请输入用户名：");


        while (!username) {
            username = prompt("请输入用户名：");
        }

        createSocket(username);

        window.onload = function () {
            // 显示当前登陆的用户名
            $("#username").text(username);
        };

        function sendMsg() {
            let content = $("#content").val();
            $.post('/message/send', {username: username, msg: content}, function (res) {
                $("#content").val("");
            });
        }
    </script>
</head>
<body>
当前用户：<span id="username"></span> <br> 当前在线人数：<span id="onlineNum">0</span> <br>
<button onclick="sendMsg()">发送消息</button>
<br>
<textarea name="content" id="content" cols="30" rows="10"></textarea>
</body>
</html>